package com.jinlia.show.modules.base.wxapp.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.jinlia.show.common.core.entity.BaseEntity;
import com.jinlia.show.modules.base.config.DynamicSchemaConfig;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Data
@TableName(value = "wxapp_app_config", schema = DynamicSchemaConfig.schema_wxapp)
public class AppConfig extends BaseEntity {
    @TableId
    private Long id;
    /**
     * appId
     */
    private String appId;
    /**
     * app密码
     */
    private String appSecret;
    /**
     * 名称
     */
    private String appName;

    /**
     * 电话
     */
    private String phone;

    /**
     * 地址
     */
    private String address;

    /**
     * 经度坐标
     */
    private Double longitude;
    /**
     * 维度坐标
     */
    private Double latitude;
    /**
     * 营业时间开始
     */
    /**
     * 预约时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    private LocalTime openHourStart;
    /**
     * 营业时间结束
     */
    /**
     * 预约时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    private LocalTime openHourEnd;
    /**
     * 默认运费
     */
    private BigDecimal defaultFreight;

    /**
     * 默认折扣
     */
    private BigDecimal defaultDiscount;

    /**
     * 销售类型,1:堂食,2:外卖 3:自提
     * 组合，1,2,3
     */
    private String saleType;
    @TableField(exist = false)
    private List<String> saleTypeList;

    public void setSaleType(String saleType) {
        this.saleType = saleType;
        if (StringUtils.hasLength(saleType)) {
            saleTypeList = Arrays.stream(saleType.split(",")).collect(Collectors.toList());
        }
    }

    public void setSaleTypeList(List<String> saleTypeList) {
        this.saleTypeList = saleTypeList;
        this.saleType = saleTypeList.stream().collect(Collectors.joining(","));
    }
}
